//
//  BaseModel.m
//  UI22_项目框架
//
//  Created by 15 on 15/7/3.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel

#pragma mark - dealloc

- (void)dealloc
{
    [super dealloc];
}

#pragma mark - 初始化方法

- (instancetype)initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        //KVC 赋值
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}
#pragma mark - 便利构造器

+ (instancetype)baseModelWithDic:(NSDictionary *)dic
{
    id objc = [[[[self class] alloc] initWithDic:dic] autorelease];
    return objc;
}

#pragma mark - 转化方法
+ (NSMutableArray *)arrayWirhModelByAppay:(NSArray *)array
{
    NSMutableArray *arr = [NSMutableArray array];
    for (NSDictionary *dic in array) {
        // 自动释放池
        @autoreleasepool {
            // 创建对象
            id model = [[self class] baseModelWithDic:dic];
            // 添加数组
            [arr addObject:model];
        }
    }
    return arr;
}

#pragma mark - KVC容错方法
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    //    id接口id和需要调用id相同时,做一下区分.用kVC必须调用这种方法,否则会crash.
    if ([key isEqualToString:@"id"]) {
        self.bId=value;
    }
    if ([key isEqualToString:@"description"]) {
        self.MXDescription=value;
    }
}

- (id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}


@end
